{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import smtplib\n",
    "from email.mime.text import MIMEText  \n",
    "# 引入smtplib和MIMEText\n",
    "from time import sleep"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Done.sent email success\n"
     ]
    }
   ],
   "source": [
    "host = 'smtp.126.com' # 设置发件服务器地址\n",
    "port = 465 # 设置发件服务器端口号。注意，这里有SSL和非SSL两种形式，现在一般是SSL方式\n",
    "\n",
    "sender = 'rubikshen@126.com' # 设置发件邮箱，一定要自己注册的邮箱\n",
    "pwd = 'shenANDqiu520' # 设置发件邮箱的授权码密码，根据163邮箱提示，登录第三方邮件客户端需要授权码\n",
    "\n",
    "receiver = '67070868@qq.com' # 设置邮件接收人，可以是QQ邮箱\n",
    "body = '<h1>处理完成</h1>' # 设置邮件正文，这里是支持HTML的\n",
    "msg = MIMEText(body, 'html') # 设置正文为符合邮件格式的HTML内容\n",
    "msg['subject'] = '打卡通知' # 设置邮件标题\n",
    "msg['from'] = sender  # 设置发送人\n",
    "msg['to'] = receiver  # 设置接收人\n",
    "\n",
    "try:\n",
    "    s = smtplib.SMTP_SSL(host, port)  # 注意！如果是使用SSL端口，这里就要改为SMTP_SSL\n",
    "    s.login(sender, pwd)  # 登陆邮箱\n",
    "    s.sendmail(sender, receiver, msg.as_string())  # 发送邮件！\n",
    "    print('Done.sent email success')\n",
    "except smtplib.SMTPException as err:\n",
    "    print('Error.sent email fail', err)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
